﻿@page "/"
@inject IJSRuntime JS
@inject IViteManifest Manifest
@inject IViteDevServerStatus ViteStatusService
@inject IHostEnvironment Environment

<PageTitle>Index</PageTitle>

<div>
	<a href="https://vitejs.dev" target="_blank">
		<img src="vite.svg" class="logo" alt="Vite logo" />
	</a>
	<a href="https://dotnet.microsoft.com/" target="_blank">
		<img src="dotnet.svg" class="logo" alt="Dotnet logo" />
	</a>
	<a href="https://www.typescriptlang.org/" target="_blank">
		<img src="typescript.svg" class="logo vanilla" alt="TypeScript logo" />
	</a>
	<h1>Vite + ASP.NET + TypeScript</h1>
	<div class="card">
		<button @ref="counterButton" id="counter" type="button"></button>
	</div>
	<p class="read-the-docs">
		Click on the Vite, ASP.NET and TypeScript logos to learn more
	</p>
</div>


@code {
	private ElementReference counterButton;

	protected override async Task OnAfterRenderAsync(bool firstRender)
	{
		if (firstRender)
		{
			var mainModule = ViteStatusService.IsEnabled
				? $"{ViteStatusService.ServerUrlWithBasePath}/main.ts"
				: $"/{Manifest["main.ts"]!.File}";
			await JS.InvokeAsync<IJSObjectReference>("import", mainModule);
		}
	}
}
